package com.hnchances.controller;

import com.hnchances.service.LoginService;
import com.hnchances.vo.RegisterRequest;
import com.hnchances.vo.UpdateRequest;
import com.hnchances.vo.ResponseResult; // 新增响应结果类
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Slf4j
@RestController
@RequestMapping("/roles")
public class LoginController {

    @Autowired
    private LoginService loginService;

    /**
     * 用户注册接口
     *
     * @param registerRequest 注册请求参数
     * @return 注册结果
     */
    @PostMapping("/register")
    public ResponseResult register(@RequestBody RegisterRequest registerRequest) {
        boolean isSuccess = loginService.register(registerRequest);
        return new ResponseResult(isSuccess, isSuccess ? "注册成功" : "注册失败");
    }

    /**
     * 用户修改接口
     *
     * @param updateRequest 修改请求参数
     * @return 修改结果
     */
    @PutMapping("/update")
    public ResponseResult update(@RequestBody UpdateRequest updateRequest) {
        boolean isSuccess = loginService.update(updateRequest);
        return new ResponseResult(isSuccess, isSuccess ? "修改成功" : "修改失败");
    }
}